package com.slipper.ai.vector;

import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentMetadata;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class VectorContent {
    private String id;
    private String text;
    private Map<String, Object> metadata;
    private float[] embedding;

    public VectorContent(String id, String text, Map<String, Object> metadata, float[] embedding) {
        this.id = id;
        this.text = text;
        this.metadata = Map.copyOf(metadata);
        this.embedding = Arrays.copyOf(embedding, embedding.length);
    }

    public Document toDocument(Double score) {
        HashMap<String, Object> metadata = new HashMap<>(this.metadata);
        metadata.put(DocumentMetadata.DISTANCE.value(), (double)1.0F - score);
        return Document.builder().id(this.id).text(this.text).metadata(metadata).score(score).build();
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getId() {
        return this.id;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getText() {
        return this.text;
    }

    public void setMetadata(Map<String, Object> metadata) {
        this.metadata = metadata;
    }

    public Map<String, Object> getMetadata() {
        return this.metadata;
    }

    public void setEmbedding(float[] embedding) {
        this.embedding = embedding;
    }

    public float[] getEmbedding() {
        return Arrays.copyOf(this.embedding, this.embedding.length);
    }
}
